<!--
 * @Description:手动对账
-->
<template>
  <div v-loading="page.bodyLoading" element-loading-text="对账中" element-loading-spinner="el-icon-loading" class="registered-container totalRevenue appMainWarp">
    <el-form :inline="true" :model="searchKey" class="demo-form-inline">
      <el-form-item label="交易时间:">
        <el-date-picker
          v-model="searchKey.time"
          type="date"
          placeholder="选择日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onLoad">重新对账</el-button>
      </el-form-item>
    </el-form>

    <template>
      <el-table
        ref="table"
        v-loading="page.tableLoading"
        v-el-height-adaptive-table="{bottomOffset: 90}"
        max-height="500px"
        center
        class="table"
        :data="searchData"
        stripe
        border
      >
        <el-table-column label="时间" align="center" prop="time">
          <template slot-scope="scope">{{ scope.row.date||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="0"
          prop="system"
          label="支付场景"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.system||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="1"
          prop="self_total_fee"
          label="支付场景收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.self_total_fee||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="2"
          prop="his_total_fee"
          label="HIS系统收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.his_total_fee	||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="3"
          prop="bank_total_fee"
          label="支付系统收入"
          align="center"
        >
          <template slot-scope="scope">{{ scope.row.bank_total_fee	||'0' }}</template>
        </el-table-column>
        <el-table-column
          :key="4"
          label="支付场景—HIS系统"
          align="center"
          prop="self_his"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.self_his > 0|| scope.row.self_his < 0? 'abnormal':'normal']"
              @click="jumpClick(scope.row,1,scope.row.self_his)"
            >{{ scope.row.self_his ||'0' }}</div>
          </template>
        </el-table-column>

        <el-table-column
          :key="5"
          label="支付场景—支付系统"
          align="center"
          prop="self_bank"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.self_bank >0 || scope.row.self_bank <0?'abnormal':'normal']"
              @click="jumpClick(scope.row,2,scope.row.self_bank)"
            >{{ scope.row.self_bank ||'0' }}</div>
          </template>
        </el-table-column>

        <el-table-column
          :key="6"
          label="HIS系统—支付系统"
          align="center"
          prop="his_bank"
        >
          <template slot-scope="scope">
            <div
              :class="[scope.row.his_bank>0 || scope.row.his_bank<0?'abnormal':'normal']"
              @click="jumpClick(scope.row,3,scope.row.his_bank)"
            >{{ scope.row.his_bank||'0' }}</div>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <pagination
      :total="page.totalRow"
      :page.sync="page.currentPage"
      :limit.sync="page.pageSize"
      @pagination="onSearch"
    />
  </div>
</template>

<script>
import elHeightAdaptiveTable from '@/directive/el-table'
// import { getConfigType } from '@/api/transactRecords/index'
import { realtimecompare, sumCompare } from '@/api/generaLedger/index'
import Pagination from '@/components/Pagination' // 分页
export default {
  name: 'Hand',
  components: {
    Pagination
  },
  directives: { elHeightAdaptiveTable },

  data() {
    return {
      compare_type: '', // 入参
      searchKey: {
        time: '', // 交易日期
        hospital_area_no: '', // 选择院区
        Hospital: [],
        system_no: '100', // 平台
        System: [],
        reconciliation: '', // 对账业务
        reconciliationList: []
      },

      searchData: [],
      date_type: '', // 按什么显示
      page: {
        bodyLoading: false,
        tableLoading: false,
        currentPage: 1, // 当前页
        pageSize: 20, // 默认条数
        totalRow: 0, // 总条数
        totalPage: 0 // 总页数
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e7
        }
      },
      compare: '', // 对账业务
      system: '' // 平台
    }
  },

  created() {
    this.searchKey.time = this.utils.getDay(-1, '-')
  },
  mounted() {
    // this.getConfig()
    // this.onLoad()
  },
  methods: {
    // 系统配置搜索
    // getConfig() {
    //   var that = this
    //   var params = {}
    //   getConfigType(params)
    //     .then(res => {
    //       that.searchKey.Hospital = res.data.hospital
    //       that.searchKey.System = res.data.scene
    //       that.searchKey.reconciliationList = res.data.compare
    //     })
    //     .catch(() => {})
    // },
    // 查询列表
    onLoad() {
      this.page.currentPage = 1
      this.onSearch()
    },
    onSearch() {
      var params = {}
      var that = this
      params.type = '2'
      params.date = that.searchKey.time // 每页展示条数
      that.page.bodyLoading = true
      realtimecompare(params)
        .then((res) => {
          that.page.bodyLoading = false
          // this.$message({
          //   type: 'success',
          //   message: '拉取成功'
          // })
          // this.compare_type = res.data.compare_type
          // this.searchKey.time = res.data.date
          this.getSumCompare(res.data.compare_type, res.data.date)
        })
        .catch(() => {
          that.page.bodyLoading = false
          this.$message({
            type: 'error',
            message: '拉取失败'
          })
          that.searchData = []
        })
    },
    jumpselfHis(item, date_type, self_his) {
      if (item.self_his === 0) {
        this.$router.push({
          path: ''
        })
      } else {
        this.$router.push({
          path: '/generaLedger/totalRevenueDetail',
          query: {
            date: item.date,
            date_type: this.date_type,
            compare_bus: this.self_his
          }
        })
      }
    },
    jumpselfBank(item, date_type, self_bank) {
      if (item.self_bank === 0) {
        this.$router.push({
          path: ''
        })
      } else {
        this.$router.push({
          path: '/generaLedger/totalRevenueDetail',
          query: {
            date: item.date,
            date_type: this.date_type,
            compare_bus: this.self_bank
          }
        })
      }
    },
    jumphisBank(item, date_type, his_bank) {
      if (item.his_bank === 0) {
        this.$router.push({
          path: ''
        })
      } else {
        this.$router.push({
          path: '/generaLedger/totalRevenueDetail',
          query: {
            date: item.date,
            date_type: this.date_type,
            compare_bus: this.his_bank
          }
        })
      }
    },
    jumpClick(item, type, val) {
      // if (val === 0 || val === '0.00') {
      //   return
      // } else {
      this.$router.push({
        path: '/generaLedger/totalRevenue/totalRevenueDetail/index',
        query: {
          currentime: item.date,
          startime: this.searchKey.time[0],
          endtime: this.searchKey.time[1],
          comparetype: type
        }
      })
      // }
    },
    getSumCompare(type, date) {
      var params = {}
      var that = this
      params.daytype = 'day'
      params.bustype = type
      params.startime = date
      params.endtime = date
      that.page.tableLoading = true
      sumCompare(params)
        .then((res) => {
          that.page.tableLoading = false
          that.searchData = res.data.result
          that.page.totalPage = res.data.pages
          that.page.totalRow = parseInt(res.data.count)
        })
        .catch(() => {
          that.page.tableLoading = false
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.totalRevenue {
  position: relative;
  width: 100%;
  .demo-form-inline {
    .el-button--primary {
      background-color: #579ef8 !important;
      color: #fff !important;
    }
    .el-button {
      background-color: #e8f4ff;
      color: #579ef8;
      border: 1px solid rgba(87, 158, 248, 1);
    }
  }
  .abnormal {
    color: red;
    text-decoration: underline;
    cursor: pointer;
  }
  .normal {
    color: rgb(113, 118, 133);
    cursor: pointer;
  }
}
</style>

